package peer.dstdb.message;

import java.net.DatagramPacket;

import peer.Message;
import peer.tools.ByteShortSwitch;
import peer.tools.Mdb;

public class SourceSumMessage extends Message{
	public short sType=peer.tools.MessageType.sType_DB_SourceSumMessage1;
	byte[] dpData=null;
	Mdb mdb;
	public SourceSumMessage(Mdb mdb){
		this.mdb=mdb;
		dpData=new byte[20];
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		System.arraycopy(mdb.md, 0, dpData, 4,16);
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public SourceSumMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		byte[] md=new byte[16];
		System.arraycopy(dpData, 4, md, 0, 16);
		mdb=new Mdb(md);
	}
	
	public Mdb getMdb(){
		return mdb;
	}
}
